<template>
  <el-dialog title="全局设置"
             class="global-setting-dialog"
             :visible.sync="showDialog"
             v-loading="loading">
    <el-form :model="form">
      <el-form-item label="爬虫每秒执行的任务数量" required>
        <el-input v-model="form.room_queue"/>
        <div>考虑到爬虫服务器都是最低性能的型号，应该尽量保持小数量</div>
      </el-form-item>
      <el-form-item label="活跃主播的直播时长条件（分钟）" required>
        <el-input v-model="form.active_minutes"/>
        <div>直播时长大于这个时间才会成为当天的活跃主播</div>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close" type="text">取消</el-button>
      <el-button type="primary" @click="submit">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    name: 'globalSetting',
    data() {
      return {
        loading: false,
        showDialog: false,
        form: {},
      };
    },
    methods: {
      show() {
        this.showDialog = true;
        this.load();
      },
      close() {
        this.showDialog = false;
      },
      async submit() {
        const res = await this.$http.post('/api/global-config', this.form);
        if (res instanceof Error)
          return this.$alert(res.message, {type: 'error'});
        this.$message({message: '成功保存', type: 'success'});
      },
      async load() {
        this.loading = true;
        const res = await this.$http.get('/api/global-config');
        this.form = res.data;
        this.loading = false;
      },
    },
    mounted() {
    },
  };
</script>

<style>
  .global-setting-dialog > .el-dialog {
    width: 600px;
  }
</style>